package com.foundryx.shared.response;

import java.util.List;

/**
 * @className: PageResult
 * @author: ocxz1
 * @date: 2025/6/25 上午11:27
 * @Version: 1.0
 * @description: fx-share-resources
 */
public class PageResult<T> extends Result<PageInfo<T>>{

    public static <T> PageResult<T> of(List<T> list, long total, int pageNum, int pageSize) {
        PageInfo<T> pageInfo = PageInfo.page(list, total, pageNum, pageSize);
        return PageResult.toResult(pageInfo);
    }

    public static <T> PageResult<T> of(List<T> list, long total) {
        PageInfo<T> pageInfo = PageInfo.page(list, total);
        return PageResult.toResult(pageInfo);
    }

    public static <T> PageResult<T> empty() {
        PageInfo<T> pageInfo = PageInfo.empty();
        return PageResult.toResult(pageInfo);
    }

    public static <T> PageResult<T> toResult(PageInfo<T> pageInfo) {
        PageResult<T> result = new PageResult<>();
        result.setCode(CommonResultCode.SUCCESS.getCode());
        result.setMessage("success");
        result.setData(pageInfo);
        return result;
    }
}
